package com.mjw.zstu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mjw.zstu.entity.ShippingAddress;
import com.mjw.zstu.mapper.AddressMapper;
import com.mjw.zstu.resultDto.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.List;

@Service
public class AddressService {
    @Autowired
    AddressMapper addressMapper;
    //新增
    public JsonResult add(ShippingAddress shippingAddress){
        addressMapper.insert(shippingAddress);
        return new JsonResult(200,"添加成功",null);
    }
    public JsonResult edit(ShippingAddress shippingAddress){
        addressMapper.updateById(shippingAddress);
        return new JsonResult(200,"编辑成功",null);
    }
    public JsonResult delete(int id){
        addressMapper.deleteById(id);
        return new JsonResult(200,"删除成功",null);
    }
    public JsonResult Userlist(int id){
        ShippingAddress shippingAddress = new ShippingAddress();
        shippingAddress.setUser_id(id);
        QueryWrapper wrapper=  new QueryWrapper(shippingAddress);
        List l=addressMapper.selectList(wrapper);
        return new JsonResult(200,"获取成功",l);
    }
    public JsonResult Companylist(int id){
        ShippingAddress shippingAddress=new ShippingAddress();
        shippingAddress.setCompany_id(id);
        QueryWrapper queryWrapper=new QueryWrapper(shippingAddress);
        List l=addressMapper.selectList(queryWrapper);
        return new JsonResult(200,"获取成功",l);
    }
}
